/*
 * jQuery Easing v1.3 - http://gsgd.co.uk/sandbox/jquery/easing/
 *
 * Uses the built in easing capabilities added In jQuery 1.1
 * to offer multiple easing options
 *
 * TERMS OF USE - jQuery Easing
 * 
 * Open source under the BSD License. 
 * 
 * Copyright © 2008 George McGinley Smith
 * All rights reserved.
 * 
 * Redistribution and use in source and binary forms, with or without modification, 
 * are permitted provided that the following conditions are met:
 * 
 * Redistributions of source code must retain the above copyright notice, this list of 
 * conditions and the following disclaimer.
 * Redistributions in binary form must reproduce the above copyright notice, this list 
 * of conditions and the following disclaimer in the documentation and/or other materials 
 * provided with the distribution.
 * 
 * Neither the name of the author nor the names of contributors may be used to endorse 
 * or promote products derived from this software without specific prior written permission.
 * 
 * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS" AND ANY 
 * EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES OF
 * MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE
 *  COPYRIGHT OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL,
 *  EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE
 *  GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED 
 * AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING
 *  NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED 
 * OF THE POSSIBILITY OF SUCH DAMAGE. 
 *
*/

// t: current time, b: begInnIng value, c: change In value, d: duration
jQuery.easing['jswing'] = jQuery.easing['swing'];

jQuery.extend( jQuery.easing,
{
	def: 'easeOutQuad',
	swing: function (x, t, b, c, d) {
		//alert(jQuery.easing.default);
		return jQuery.easing[jQuery.easing.def](x, t, b, c, d);
	},
	easeInQuad: function (x, t, b, c, d) {
		return c*(t/=d)*t + b;
	},
	easeOutQuad: function (x, t, b, c, d) {
		return -c *(t/=d)*(t-2) + b;
	},
	easeInOutQuad: function (x, t, b, c, d) {
		if ((t/=d/2) < 1) return c/2*t*t + b;
		return -c/2 * ((--t)*(t-2) - 1) + b;
	},
	easeInCubic: function (x, t, b, c, d) {
		return c*(t/=d)*t*t + b;
	},
	easeOutCubic: function (x, t, b, c, d) {
		return c*((t=t/d-1)*t*t + 1) + b;
	},
	easeInOutCubic: function (x, t, b, c, d) {
		if ((t/=d/2) < 1) return c/2*t*t*t + b;
		return c/2*((t-=2)*t*t + 2) + b;
	},
	easeInQuart: function (x, t, b, c, d) {
		return c*(t/=d)*t*t*t + b;
	},
	easeOutQuart: function (x, t, b, c, d) {
		return -c * ((t=t/d-1)*t*t*t - 1) + b;
	},
	easeInOutQuart: function (x, t, b, c, d) {
		if ((t/=d/2) < 1) return c/2*t*t*t*t + b;
		return -c/2 * ((t-=2)*t*t*t - 2) + b;
	},
	easeInQuint: function (x, t, b, c, d) {
		return c*(t/=d)*t*t*t*t + b;
	},
	easeOutQuint: function (x, t, b, c, d) {
		return c*((t=t/d-1)*t*t*t*t + 1) + b;
	},
	easeInOutQuint: function (x, t, b, c, d) {
		if ((t/=d/2) < 1) return c/2*t*t*t*t*t + b;
		return c/2*((t-=2)*t*t*t*t + 2) + b;
	},
	easeInSine: function (x, t, b, c, d) {
		return -c * Math.cos(t/d * (Math.PI/2)) + c + b;
	},
	easeOutSine: function (x, t, b, c, d) {
		return c * Math.sin(t/d * (Math.PI/2)) + b;
	},
	easeInOutSine: function (x, t, b, c, d) {
		return -c/2 * (Math.cos(Math.PI*t/d) - 1) + b;
	},
	easeInExpo: function (x, t, b, c, d) {
		return (t==0) ? b : c * Math.pow(2, 10 * (t/d - 1)) + b;
	},
	easeOutExpo: function (x, t, b, c, d) {
		return (t==d) ? b+c : c * (-Math.pow(2, -10 * t/d) + 1) + b;
	},
	easeInOutExpo: function (x, t, b, c, d) {
		if (t==0) return b;
		if (t==d) return b+c;
		if ((t/=d/2) < 1) return c/2 * Math.pow(2, 10 * (t - 1)) + b;
		return c/2 * (-Math.pow(2, -10 * --t) + 2) + b;
	},
	easeInCirc: function (x, t, b, c, d) {
		return -c * (Math.sqrt(1 - (t/=d)*t) - 1) + b;
	},
	easeOutCirc: function (x, t, b, c, d) {
		return c * Math.sqrt(1 - (t=t/d-1)*t) + b;
	},
	easeInOutCirc: function (x, t, b, c, d) {
		if ((t/=d/2) < 1) return -c/2 * (Math.sqrt(1 - t*t) - 1) + b;
		return c/2 * (Math.sqrt(1 - (t-=2)*t) + 1) + b;
	},
	easeInElastic: function (x, t, b, c, d) {
		var s=1.70158;var p=0;var a=c;
		if (t==0) return b;  if ((t/=d)==1) return b+c;  if (!p) p=d*.3;
		if (a < Math.abs(c)) { a=c; var s=p/4; }
		else var s = p/(2*Math.PI) * Math.asin (c/a);
		return -(a*Math.pow(2,10*(t-=1)) * Math.sin( (t*d-s)*(2*Math.PI)/p )) + b;
	},
	easeOutElastic: function (x, t, b, c, d) {
		var s=1.70158;var p=0;var a=c;
		if (t==0) return b;  if ((t/=d)==1) return b+c;  if (!p) p=d*.3;
		if (a < Math.abs(c)) { a=c; var s=p/4; }
		else var s = p/(2*Math.PI) * Math.asin (c/a);
		return a*Math.pow(2,-10*t) * Math.sin( (t*d-s)*(2*Math.PI)/p ) + c + b;
	},
	easeInOutElastic: function (x, t, b, c, d) {
		var s=1.70158;var p=0;var a=c;
		if (t==0) return b;  if ((t/=d/2)==2) return b+c;  if (!p) p=d*(.3*1.5);
		if (a < Math.abs(c)) { a=c; var s=p/4; }
		else var s = p/(2*Math.PI) * Math.asin (c/a);
		if (t < 1) return -.5*(a*Math.pow(2,10*(t-=1)) * Math.sin( (t*d-s)*(2*Math.PI)/p )) + b;
		return a*Math.pow(2,-10*(t-=1)) * Math.sin( (t*d-s)*(2*Math.PI)/p )*.5 + c + b;
	},
	easeInBack: function (x, t, b, c, d, s) {
		if (s == undefined) s = 1.70158;
		return c*(t/=d)*t*((s+1)*t - s) + b;
	},
	easeOutBack: function (x, t, b, c, d, s) {
		if (s == undefined) s = 1.70158;
		return c*((t=t/d-1)*t*((s+1)*t + s) + 1) + b;
	},
	easeInOutBack: function (x, t, b, c, d, s) {
		if (s == undefined) s = 1.70158; 
		if ((t/=d/2) < 1) return c/2*(t*t*(((s*=(1.525))+1)*t - s)) + b;
		return c/2*((t-=2)*t*(((s*=(1.525))+1)*t + s) + 2) + b;
	},
	easeInBounce: function (x, t, b, c, d) {
		return c - jQuery.easing.easeOutBounce (x, d-t, 0, c, d) + b;
	},
	easeOutBounce: function (x, t, b, c, d) {
		if ((t/=d) < (1/2.75)) {
			return c*(7.5625*t*t) + b;
		} else if (t < (2/2.75)) {
			return c*(7.5625*(t-=(1.5/2.75))*t + .75) + b;
		} else if (t < (2.5/2.75)) {
			return c*(7.5625*(t-=(2.25/2.75))*t + .9375) + b;
		} else {
			return c*(7.5625*(t-=(2.625/2.75))*t + .984375) + b;
		}
	},
	easeInOutBounce: function (x, t, b, c, d) {
		if (t < d/2) return jQuery.easing.easeInBounce (x, t*2, 0, c, d) * .5 + b;
		return jQuery.easing.easeOutBounce (x, t*2-d, 0, c, d) * .5 + c*.5 + b;
	}
});

/*
 *
 * TERMS OF USE - EASING EQUATIONS
 * 
 * Open source under the BSD License. 
 * 
 * Copyright © 2001 Robert Penner
 * All rights reserved.
 * 
 * Redistribution and use in source and binary forms, with or without modification, 
 * are permitted provided that the following conditions are met:
 * 
 * Redistributions of source code must retain the above copyright notice, this list of 
 * conditions and the following disclaimer.
 * Redistributions in binary form must reproduce the above copyright notice, this list 
 * of conditions and the following disclaimer in the documentation and/or other materials 
 * provided with the distribution.
 * 
 * Neither the name of the author nor the names of contributors may be used to endorse 
 * or promote products derived from this software without specific prior written permission.
 * 
 * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS" AND ANY 
 * EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES OF
 * MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE
 *  COPYRIGHT OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL,
 *  EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE
 *  GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED 
 * AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING
 *  NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED 
 * OF THE POSSIBILITY OF SUCH DAMAGE. 
 *
 */
/* Adobe Tag Container Loader version: 1.0.7
Copyright 1996-2012 Adobe, Inc. All Rights Reserved
More info available at http://www.omniture.com */
var s=new TagContainerLoader()
s.tagContainerDC="d2"
s.tagContainerNamespace="twctsg"
s.tagContainerName="nonbuyflowscode"
s.loadTagContainer()

/************* DO NOT ALTER ANYTHING BELOW THIS LINE ! **************/
function TagContainerLoader(){var t=this,w=t.w=window;t.d=w.document;t._c='s_l';if(!w.s_c_il){w.s_c_il=[];w.s_c_in=0}t._il=w.s_c_il;t._in=w.s_c_in;t._il[t._in]=t;w.s_c_in++;t.timeout=5000;t.to=
new Function('var t=s_c_il['+t._in+'];if(t.mt)t.mt(0)');t.loadTagContainer=function(){var t=this,l,p=t.d.body,n,a=t.tagContainerServer?t.tagContainerServer:'www.adobetag.com',b=
t.tagContainerServerSecure?t.tagContainerServerSecure:a,c=t.d.cookie,d=t.tagContainerEnv?t.tagContainerEnv:(c?(c.indexOf('s_tagEnv=dev')>=0?'dev':(c.indexOf('s_tagEnv=stage')>=0?'stage':'live')):
'live'),u=(t.w.location.protocol.toLowerCase().indexOf('https')>=0?'https://'+b:'http://'+a)+'/'+(t.tagContainerDC?t.tagContainerDC+'/':'')+t.tagContainerNamespace+'/'+d+'/'+t.tagContainerName+'.js'
if(t.tagContainerURL)u=t.tagContainerURL;if(t.timeout)t.ti=setTimeout(t.to,t.timeout);if(t.d.getElementsByTagName){l=t.d.getElementsByTagName('HEAD');if(l&&l[0])p=l[0]}else p=0;if(
p&&!t.tagContainerSynchronous){n=t.d.createElement('SCRIPT');if(n){n.type='text/javascript';n.setAttribute('async','async');n.src=u;if(p.firstChild)p.insertBefore(n,p.firstChild);else p.appendChild(n)
}}else t.d.write('<sc'+'ript language="JavaScript" type="text/javascript" sr'+'c="'+u+'"></sc'+'ript>')};t.fs=function(x,y){if(x&&y){var a=x.split(','),b=y.split(','),i,j;for(i=0;i<a.length;i++){
for(j=0;j<b.length;j++)if(a[i]==b[j])return 1}}return 0};t.aa=function(a){var b=0,i;if(a){b=[];for(i=0;i<a.length;i++)b[i]=a[i]}return b};t.wl=[];t.wq=[];t.createAsynchronousCustomTagHandler=function(
o,f){var t=this,x,i;if(!f){f=o;o=0;x=t.w}else{if(!t.w[o])t.w[o]={};x=t.wl[o]=t.w[o]}if(typeof(f)!='object')f=[f];for(i=0;i<f.length;i++)if(!x[f[i]])x[f[i]]=new Function('var t=s_c_il['+t._in+
'];t.wq[t.wq.length]={'+(o?'o:"'+o+'",':'')+'f:"'+f[i]+'",a:t.aa(arguments)}')};t.as=function(x){var y=[],i;for(i=1;i<x.length;i++)y[y.length]=x[i];return y};t.s=0;t.contextData={}
t.retrieveLightData={};if(!w.s_giq)w.s_giq=[];t._gi=w.s_gi;w.s_gi=new Function('u','var t=s_c_il['+t._in+
'],w=t.w,l=t._il,i,j,x,s;u=u.toLowerCase();if(l)for(j=0;j<2;j++)for(i=0;i<l.length;i++){s=l[i];x=s._c;if((!x||x=="s_c"||(j>0&&x=="s_l"))&&s.oun&&(s.oun==u||(s.fs&&s.sa&&s.fs(s.oun,u)))){'+
'if(s.sa)s.sa(u);return s}}if(!t.oun){t.sa(u);return t}if(t._gi)return t._gi(u);s=new TagContainerLoader();s.tagContainerName="s_tca_"+w.s_giq.length;s.sa(u);w.s_giq[w.s_giq.length]=s;return s');t.sa=
function(u){var t=this;if(t.s)t.s.sa(u);t.un=u;if(!t.oun)t.oun=u;else if(!t.fs(t.oun,u))t.oun+=','+u};t.tq=[];t.track=t.t=function(vo){var t=this,m;if(t.s)return t.s.t(vo);if(!vo)vo={};for(m in t){if(
m!='un'||t.u!=t.un)vo[m]=t[m]}t.tq[t.tq.length]=vo;t.lnk=t.linkName=t.linkType='';return '';};t.trackLink=t.tl=function(o,u,n,vo){var t=this;if(t.s)return t.s.tl(o,u,v,vo);t.lnk=o;t.linkType=u
t.linkName=n;return t.t(vo)};t.trackLight=function(p,ss,i,vo){var t=this;if(t.s)return t.s.trackLight(p,ss,i,vo);t.lightProfileID=p;t.lightStoreForSeconds=ss;t.lightIncrementBy=i;return t.t(vo)}
t.lmq=[];t.loadModule=function(n,u,d){var t=this;if(t.s)return t.s.loadModule(n,u,d);t.lmq[t.lmq.length]={n:n,u:u,d:d};return 0};t.ml=[];t.mmq=[];t.mo=function(m,f){var t=this,i;t.ml[m]=t[m]={};if(f)
for(i=0;i<f.length;i++)t[m][f[i]]=new Function('var t=s_c_il['+t._in+'];t.mmq[t.mmq.length]={m:"'+m+'",f:"'+f[i]+'",a:t.aa(arguments)}')};t.mo('Media',['open','play','stop','close','track']);t.mo(
'Survey',['launch']);t.mci=[];t.mn=[];t.mc=function(n,m,p,k){var t=this,b,l=0;if(typeof(mboxFactoryDefault)=='undefined'||t.d.getElementById(m)==null)return;if(!mboxFactoryDefault.isEnabled()){
clearInterval(t.mci[k]);t.mt(true);return}if(typeof(mboxFactoryDefault.get(t.mn[0],0))!='undefined')l=mboxFactoryDefault.get(t.mn[0],0).isShown();if(k==0||l){clearInterval(t.mci[k]);b=
mboxFactoryDefault.create(n,p.split("&"));if(b)b.load()}};if(!w.mboxCreate&&!w.mboxDefine&&!w.mboxUpdate){w.mboxVersion='mini';if(!t.d.getElementById('mboxScriptContainer'))t.d.write(
'<div id="mboxScriptContainer" style="display:none;visibility:hidden;"></div><style>.mboxDefault{visibility:hidden;}</style>');t.mt=function(f){var t=this,i,j,d;if(typeof(mboxFactoryDefault)==
'undefined'||f){for(i in t.mci)clearInterval(t.mci[i]);d=(t.d.getElementsByClassName)?t.d.getElementsByClassName('mboxDefault'):t.d.getElementsByTagName('div');for(j in d)if(d[j].className==
"mboxDefault")d[j].style.visibility="visible"}};t.mpi={};t.mp=function(x,m){var t=this;t.mpi[x]=setInterval(function(){if(typeof(mboxFactoryDefault)==='undefined')return;m();clearInterval(t.mpi[x])},
13)};w.mboxCreate=function(n){var j=0,i,m,p,k;for(i in t.mn)if(t.mn[i]==n)j++;t.mn[t.mn.length]=n;m='mboxMarker-default-'+n+'-'+j;t.d.write('<div id="'+m+
'" style="visibility:hidden;display:none">&nbsp;</div>');p=t.as(arguments).join("&");k=t.mci.length;t.mci[k]=setInterval(function(){t.mc(n,m,p,k);},5)};w.mboxDefine=function(d,n){var a=t.as(arguments)
t.mp('define_'+n,function(){mboxFactoryDefault.create(n,a,d);})};w.mboxUpdate=function(n){var a=t.as(arguments),x;x='update_'+n;t.mpi[x]=setInterval(function(){if(typeof(mboxFactoryDefault)===
'undefined'||typeof(mboxFactoryDefault.get(n))==='undefined')return;mboxFactoryDefault.update(n,a);clearInterval(t.mpi[x]);},13)};w.mboxLoadSCPlugin=function(s){(function(){if(typeof(
mboxFactoryDefault)==='undefined'||typeof(mboxExternalLoadSCPlugin)==='undefined'||(s._c=='s_l'&&!s.s)){setTimeout(arguments.callee,19);return}if(s._c=='s_l')s=s.s;mboxExternalLoadSCPlugin(s)})()};}}

jpackage('twc.errors', function() {
    var ErrorView = Backbone.View.extend({
		errorTemplate : '<div id="error-modal" class="modal hide fade" data-backdrop="true" data-keyboard="true"><div class="modal-header"></div><div class="modal-body"></div><div class="modal-footer"><button class="btn" data-dismiss="modal">Close</button></div></div>',
		modalError : '#error-modal',
		modalHeader : '#error-modal div.modal-header',
		modalBody : '#error-modal div.modal-body',

        initialize:function(opts){
			$('body').append(this.errorTemplate);

			this.$modalError = $(this.modalError);
			this.$modalHeader = $(this.modalHeader);
			this.$modalBody = $(this.modalBody);

			this.$modalError.modal({
				show: false
			});
        },
		render:function(header, body, action) {
			if (header) {
				this.$modalHeader.html("<i class='exclamation'></i>" + header + "<a class='close-link' data-dismiss='modal'>Close</a>");
			}
			if (body) {
				this.$modalBody.html(body);
			}
			if (action) {
				this.$modalError.on('hide', _.bind(action, this));
			}
			this.$modalError.modal('show');
		}
	});

	this.view = new ErrorView();
});


jpackage('twc.print', function() {
    var PrintView = Backbone.View.extend({
		style : '<style>body { overflow:auto; } pre { position:absolute; font-family: "Helvetica Neue", Helvetica, Arial, sans-serif; font-size: 13px; line-height: 18px; color: #333333; word-wrap: break-word; word-break: normal; white-space: pre-wrap; height:auto;}</style>',
	
		render : function(html) {
			this.w = window.open('', '', 'scrollbars=yes,location=no,toolbar=no,status=no,width=500,height=550,left=300,top=50');
			$(this.w.document.body).append(this.style);
			$(this.w.document.body).append(html);
			this.w.print();
		}
	});
	this.view = new PrintView();
});

jpackage('twc.alerts', function() {
	var routes = twc.utils.routes;

    var AlertModel = Backbone.Model.extend({

    });
    var AlertsCollection = Backbone.Collection.extend({
        model:AlertModel,
        url: twc.routes.get('public/global-alerts')
    });

    var AlertsView = Backbone.View.extend({
        el:'<div id="global-alerts"></div>',
        alertsTemplate: 'alerts-template',
        modalTemplate: 'alerts-modal-template',

        events:{
            'click .rightarrow': 'nextAlert',
            'click .leftarrow' : 'prevAlert'
        },

        initialize:function(opts){
            // var self = this;

            this.collection.on('reset', function(){
                var collection = this.collection;
                var tmpl = twc.utils.template(this.modalTemplate);

                // console.log('success');
                // console.log('collection', collection.models);

                if(collection.length > 0){
                    // console.log('collection.length > 0', collection.length);

                    this.$el.insertAfter("#mys-header");
                    this.render(0);

                    var $alertModals = $('<div></div>')
                    $('body').append($alertModals);

                    collection.each(function(alert, index){
                        $alertModals.append(tmpl({
                            current: index + 1,
                            data: alert.toJSON()
                        }));
                    });

                    $alertModals.on('click', '.print', this.print);
                }
            }, this);
        },
        render:function(item) {
            this.$el.html(twc.utils.template(this.alertsTemplate)({
                current: (item || 0) + 1,
                max: this.collection.length,
                data: this.collection.models[item || 0].attributes
            }))
        },
        nextAlert: function(e){
            e.preventDefault();
            var currentAlert = parseInt(this.$el.find('a').attr('href').split('#alert-modal')[1]);
            if (currentAlert === this.collection.length) {
                this.render(0);
            } else {
                this.render(currentAlert);
            }
        },
        prevAlert: function(e){
            e.preventDefault();
            var currentAlert = parseInt(this.$el.find('a').attr('href').split('#alert-modal')[1], 10);
            if (currentAlert === 1) {
                this.render(this.collection.length-1);
            } else {
                this.render(currentAlert-2);
            }
        }//,
        // print: function(e){
        //     twc.print.view.render("<pre>"+$('#alert-modal'+$(e.currentTarget).data('modalid')).html()+"</pre>");
        // }
    });


    $(function(){
        var alertsCollection = new AlertsCollection();
        var view = new AlertsView({ collection: alertsCollection });

        alertsCollection.fetch({reset:true});

        // for testing/debugging
        // alertsCollection.reset([
        //    {"actionText":"Read More","body":"Several TV channels are moving to digital format only. <a href=\"http://www.timewarnercable.com//digitaladapter\">Click here<\/a> to find out what this improvement means to you and to learn more about digital adapters. Read More ","headline":"Are you a TV subscriber?","shortHeadline":"Are you a TV subscriber?"},{"actionText":"2actionText","body":"2body","headline":"2Headline","imagePath":"2imagePath","link":"2link","previewText":"2previewText","shortHeadline":"2Short Headline"},{"actionText":"3actionText","body":"3body","headline":"3Headline","imagePath":"3imagePath","link":"3link","previewText":"3previewText","shortHeadline":"3Short Headline"},{"actionText":"4actionText","body":"4body","headline":"4Headline","imagePath":"4imagePath","link":"4link","previewText":"4previewText","shortHeadline":"4Short Headline"},{"actionText":"5actionText","body":"5body","headline":"5Headline","imagePath":"5imagePath","link":"5link","previewText":"5previewText","shortHeadline":"5Short Headline"}
        // ]);
    });
});

jpackage('twc.browserAlert', function() {
	
	this.COOKIES_DISABLED = "cookiesDisabled";
	this.UNSUPPORTED_BROWSER = "unsupportedBrowser";
	this.UNSUPPORTED_VERSION = "unsupportedVersion";
	this.IE_COMPATIBILILTY_MODE = "ieCompatibilityMode";
	
    var BrowserAlertModel = Backbone.Model.extend({

    });

    var BrowserAlertView = Backbone.View.extend({
        el:'<div id="browser-alert"></div>',
        browserAlertTemplate: 'browser-alert-template',
    
        initialize:function(opts) {	
        	this.browserInfo = this.getBrowserInfo();
        	
        	var browserIssue = this.getBrowserIssue();
        	var hideBrowserAlert = twc.utils.StorageUtil.read("hideBrowserAlert");
        	
        	if (browserIssue && !hideBrowserAlert) {
	        	var self = this;
	        	$.ajax(twc.routes.get('public/browser-alerts')).done(function(resp){
	        		if (resp && !resp.error) {
	        			var copy = resp.browserAlertsCopy;
	        			var alertMessage = copy[browserIssue];
	        			
	        			// If no copy is returned, there was an error or the feature is disabled.
	        			if (!copy || !alertMessage || $.isEmptyObject(alertMessage)) return;
	        			
	        			// Render the alert if valid copy is returned in the response
	        			self.$el.insertBefore("#mys-header");
	                	self.render(alertMessage);
	        	    }
	        	})
        	}
        },
        render:function(alertMessage) {
        	this.$el.html(twc.utils.template(this.browserAlertTemplate)(alertMessage))
        	$('.close', this.$el).click(_.bind(this.hideBrowserAlert, this));
        	$('.more', this.$el).click(_.bind(this.expandBrowserAlert, this));
        	$('.less', this.$el).click(_.bind(this.collapseBrowserAlert, this));
        },
        hideBrowserAlert:function() {
        	this.$el.remove();
        	twc.utils.StorageUtil.write("hideBrowserAlert", true);
        },
        expandBrowserAlert:function() {
        	this.$el.addClass('expanded');
        },
        collapseBrowserAlert:function() {
        	this.$el.removeClass();
        },
        getBrowserIssue:function() {
        	if (!this.checkIfCookiesEnabled())
        		return twc.browserAlert.COOKIES_DISABLED;
        	else if (!this.checkIfSupportedBrowser())
        		return twc.browserAlert.UNSUPPORTED_BROWSER;
        	else if (this.checkIfIECompatibilityMode()) 
        		return twc.browserAlert.IE_COMPATIBILILTY_MODE;
        	else if (!this.checkIfSupportedVersion())
        		return twc.browserAlert.UNSUPPORTED_VERSION;
        	
        	return;
        },
        checkIfCookiesEnabled:function() {
        	return twc.utils.CookieUtil.checkIfCookiesEnabled();
        },
        checkIfSupportedBrowser:function() {
        	return match = this.browserInfo.name.match(/(chrome|safari|firefox|msie)/i);
        },
        checkIfSupportedVersion:function() {
        	var browserName = this.browserInfo.name.toLowerCase();
        	var browserVersion = this.browserInfo.version;
        	
        	if (browserName == "firefox" && browserVersion >= 3.6)
        		return true;
        	
        	if (browserName == "chrome" && browserVersion >= 19)
        		return true;
        	
        	if (browserName == "safari" && browserVersion >= 5.05)
        		return true;
        	
        	if (browserName == "msie" && browserVersion >= 8)
        		return true;
        	
        	return false;
        },
        checkIfIECompatibilityMode:function() {
        	var userAgent = navigator.userAgent;
        	var browserName = this.browserInfo.name.toLowerCase();
        	var browserVersion = this.browserInfo.version;
        	
        	return (browserName == "msie" && browserVersion <= 7 && /trident/i.test(userAgent));
        },
        getBrowserInfo:function() {
        	var userAgent = navigator.userAgent;
            var version;
            var browser = {};
            
            var M = userAgent.match(/(chrome|safari|firefox|msie)\/?\s*(\.?\d+(\.\d+)*)/i);
            if (M && (version = userAgent.match(/version\/([\.\d]+)/i)) != null) M[2] = version[1];
            browser = M ? {name:M[1], version:M[2]} : {name:navigator.appName, version:navigator.appVersion};
            
            //Special case for IE 11
            if (!M && /trident/i.test(userAgent)) {
            	browser = {name:'msie', version:'11'};
            }
            
            //Opera
            else if (/opr/i.test(userAgent) || !!window.opera) {
            	browser.name = 'opera';
            }
            
            //AOL, AOL Explorer, and other non-supported browsers
            else if (/AOL|America Online Browser/i.test(userAgent)) {
            	browser.name = 'other';
            }
            
            // Parse strings like "5", "5.1", and "5.0.5" to a valid float value
            browser.version = parseFloat(browser.version);
            
            return browser;
        }
    });

    $(function(){
    	var view = new BrowserAlertView();
    });
});


